package com.kefu.call.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.call.service.CallStartService;
import com.kefu.call.vo.*;
import com.kefu.call.vo.CallStartVo.CallStartRptVo;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Api(tags = "呼入相关业务")
@RestController
@RequestMapping("call/callStart/")
public class CallStartController extends AbstractBaseController {
    @Resource
    private CallStartService callStartService;

    @PostMapping("callStartRecord")
    @ApiOperation(value = "呼入自定义纪录", notes = "呼入自定义纪录")
    public Result<Page<Map<String, Object>>> callStartRecord(@Validated @RequestBody CallStartRptVo searchVo) {
        return ResultGenerator.genSuccessResult(callStartService.callStartRecord(searchVo));
    }

    @PostMapping("/callStartRecordExport")
    @ApiOperation(value = "导出呼入纪录", notes = "导出呼入纪录")
    public void sessionRecordExport(@Validated @RequestBody CallStartRptVo search, HttpServletResponse response) throws IOException {
        List<Object[]> exportList = callStartService.callStartRecordExport(search);
        csvWriter(exportList, response);
    }

    @PostMapping("callStartIvrRpt")
    @ApiOperation(value = "呼入Ivr业务统计", notes = "呼入Ivr业务统计")
    public Result<CallStartIvrRptResp> callStartIvrReport(@Validated @RequestBody CallStartIvrRptVo search) {
        return ResultGenerator.genSuccessResult(callStartService.callStartIvrRpt(search));
    }

    @PostMapping("/callStartRptExport")
    @ApiOperation(value = "呼入Ivr业务统计导出", notes = "呼入Ivr业务统计导出")
    public void callStartRptExport(@Validated @RequestBody CallStartIvrRptVo search, HttpServletResponse response) throws IOException {
        List<Object[]> exportList = callStartService.callStartRptExport(search);
        csvWriter(exportList, response);
    }

    @PostMapping("callStartProvinceRpt")
    @ApiOperation(value = "呼入按省份统计", notes = "呼入按省份统计")
    public Result<List<Map<String, Object>>> callStartProvinceRpt(@Validated @RequestBody CallStartProvinceRptVo search) {
        return ResultGenerator.genSuccessResult(callStartService.callStartProvinceRpt(search));
    }

    @PostMapping("/callStartProvinceRptExport")
    @ApiOperation(value = "呼入按省份统计导出", notes = "呼入按省份统计导出")
    public void callStartProvinceRptExport(@Validated @RequestBody CallStartProvinceRptVo search, HttpServletResponse response) throws IOException {
        List<Object[]> exportList = callStartService.callStartProvinceRptExport(search);
        csvWriter(exportList, response);
    }


    @PostMapping("regionRpt")
    @ApiOperation(value = "地域分布报表", notes = "地域分布报表")
    public Result<List<Map<String, Object>>> regionRpt(@Validated @RequestBody CallStartRegionRptVo search) {
        return ResultGenerator.genSuccessResult(callStartService.regionRpt(search));
    }

    @PostMapping("/regionRptExport")
    @ApiOperation(value = "地域分布报表导出", notes = "地域分布报表导出")
    public void regionRptExport(@Validated @RequestBody CallStartRegionRptVo search, HttpServletResponse response) throws IOException {
        List<Object[]> exportList = callStartService.regionRptExport(search);
        csvWriter(exportList, response);
    }
}
